import Banner from '@/components/banner'
import Search from '@/components/search'
import sectionTitle from '@/components/section-title'
import Post from '@/components/post2'
import SmallIco from '@/components/small-ico'
import Quote from '@/components/quote'
import {
	fetchFocus,
	fetchList,
	fetchNotices,
	getLols
} from '@/api'
import {
	queryOneLevelCategory,
	queryList,
	queryArticlesBOLC,
	queryTJArticle
} from '@/api/blog.js'
import {
	queryHotArticles,
	queryToppingArticles
} from '@/api/articles'
import {
	queryPageListByLevel
} from '@/api/category.js'
import store from '@/store'
import jQuery from 'jquery'
import advertisement from '@/components/advertisement/advertisement'
import {
	getNotices
} from "@/api/notice.js"
import {
	queryPage
} from "@/api/visitor.js"
export default {
	name: 'Home',
	props: ['cate', 'words'],
	data() {
		return {
			features: [],
			postList: [],
			currPage: 1,
			hasNextPage: false,
			oneLevels: [],
			categoryId: 0,
			pageSize: 10,
			article_total: 0,
			hotArticles: [],
			dialogVisible: false,
			dialogVisible_image: '',
			poems: [],
			books: [],
			book_index: 0,
			paintings: [],
			notices: [],
			notice_index: 0,
			notice: {
				dialogVisible: false,
				title: "",
				content: ""
			},
			ab: 0,
			postList_index: 0,
			//lol资讯相关的数据
			lols: {
				pageSize: 10,
				data: [],
				total: 0,
				currPage: 1
			},
			articles_title: "推荐博文",
			//访客足迹相关的数据
			visitor: {
				pageSize: 6,
				data: [],
				total: 0,
				currPage: 1
			},
			mobile: {
				categoryNavDrawer: false,
				article: {
					pageNo: 1,
					pageSize: 10
				},
				postList: [],
				categoryId: 0,
				articles_title: "推荐博文"
			}
		}
	},
	components: {
		Banner,
		sectionTitle,
		Post,
		SmallIco,
		Quote,
		Search,
		advertisement,
	},
	computed: {
		searchWords() {
			return this.$route.params.words
		},
		category() {
			return this.$route.params.cate
		},
		hideSlogan() {
			return this.category || this.searchWords
		},
		player() {
			return this.$refs.videoPlayer.player;
		},
		xuMeiJuan() {
			return this.$store.state.xuMeiJuan
		}
	},
	methods: {
		handleSizeChange(val) {
			this.getTJArticles(val);
		},
		handleSizeChange2(val) {
			this.getLols(val - 1);
		},
		visitor_handleSizeChange(val) {
			this.getVisitorPage(val);
		},
		getHotArticles() {
			queryHotArticles().then(res => {
				this.hotArticles = res.data;
			})
		},
		getTJArticles(pageNo) {
			queryTJArticle(pageNo, this.pageSize).then(res => {
				this.article_total = res.data.total;
				this.postList = res.data.data || []
			})
		},
		fetchNotices() {
			getNotices().then(res => {
				this.notices = res.data;
			})
		},
		getLols(pageNo) {
			getLols(pageNo, this.lols.pageSize).then(res => {
				this.lols.data = res.data.data;
				this.lols.total = res.data.total;
			})
		},
		ab1() {
			if (this.ab == 2) {
				queryHotArticles().then(res => {
					this.notices = res.data;
				})
			} else if (this.ab == 0) {
				this.fetchNotices();
			} else if (this.ab == 1) {
				queryToppingArticles().then(res => {
					this.notices = res.data;
				})
			}
		},
		getVisitorPage(pageNo) {
			queryPage(pageNo, this.visitor.pageSize).then(res => {
				this.visitor.data = res.data.data;
				this.visitor.total = res.data.total;
			})
		}
	},
	watch: {

	},
	mounted() {
		this.getHotArticles();
		this.getTJArticles(0);
		this.getLols(0);
		this.getVisitorPage(0);
		this.fetchNotices();
	},
	created() {},
	//页面创建之初自动触发的事件
	beforeCreate() {
		this.$bus.emit("setIdx", 0);
	}
}
